package com.techprimers.mybatis.springbootmybatis.resource;

import com.techprimers.mybatis.springbootmybatis.mapper.PostMapper;
import com.techprimers.mybatis.springbootmybatis.model.Post;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/rest/posts")
public class PostResource {

    private PostMapper postMapper;

    public PostResource(PostMapper postMapper) {
        this.postMapper = postMapper;
    }

    // 全部
    @GetMapping("/all")
    public List<Post> getAll() {

        return postMapper.findAll();
    }

    // 模糊查询like通配符
    @GetMapping("/getByContent")
    public List<Post> getByContent() {

        String contentName = "我们都有工作可以自己管自己";

        return postMapper.findByContent(contentName);
    }


    @GetMapping("/content={userName}")
    public List<Post> checkUserName(@PathVariable("userName") String userName) {

        return postMapper.findByContent(userName);
    }
}
